package com.ychong.ychongwidget.ui

import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.os.Bundle
import android.os.Handler
import android.os.Message
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.ychong.ychongwidget.R
import com.ychong.ychongwidget.databinding.ActivitySpreadviewBinding


class SpreadViewActivity : AppCompatActivity() {
    private lateinit var binding: ActivitySpreadviewBinding
    private var valueAnimator: ValueAnimator? = null
    private var text: String = "量子通话拨号中..."
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_spreadview)

        binding.textTv.text = text

// 步骤1：设置属性数值的初始值 & 结束值
        // 步骤1：设置属性数值的初始值 & 结束值
        val initWidth1 = binding.bgIv1.layoutParams.width
        val initHeight1 = binding.bgIv1.layoutParams.height
        valueAnimator = ValueAnimator.ofFloat(
            0.8f,
            0.9f,
            1.0f,
            1.1f
        )
        valueAnimator?.duration = 800
        valueAnimator?.repeatMode = ValueAnimator.REVERSE
        valueAnimator?.repeatCount = ValueAnimator.INFINITE
        valueAnimator?.addUpdateListener { animator -> // 获得每次变化后的属性值
            val currentValue = animator.animatedValue as Float
            binding.bgIv1.layoutParams.width = (initWidth1 * currentValue).toInt()
            binding.bgIv1.layoutParams.height = (initHeight1 * currentValue).toInt()
            binding.bgIv1.requestLayout()
        }
        valueAnimator?.start()
    }

    override fun onDestroy() {
        super.onDestroy()
        valueAnimator?.cancel()
        valueAnimator = null
    }
}